package com.thiscc.sum.utils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.thiscc.sum.common.MongoDBManager;
import com.thiscc.sum.constance.TableName;

public class ReduceCountUtils {
    /**
     *  减少功能消息条数
     * 
     */
    //数据库操作对象
    private static MongoDBManager db = MongoDBManager.getInstance();

    public static boolean reduceMsgCount(String s_uuid, String s_pid, int reduce) {

        boolean flag;

        //条件
        DBObject conditionDB = new BasicDBObject();
        conditionDB.put("uuid", s_uuid);
        conditionDB.put("pid", s_pid);

        //修改数据
        DBObject updateDB = new BasicDBObject();

        if (reduce > 0 && reduce <= 20) {

            updateDB.put("count", -reduce);
        } else if (reduce > 20) {

            updateDB.put("count", -20);
        }

        flag = db.updateInt(TableName.T_WORK, conditionDB, updateDB);

        return flag;
    }
}
